feat(FXC-5154) Warn gmsh min cylinder radii#3217
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds validation to warn users when cylinder radii are too small for gmsh meshing in heat-charge simulations. The feature helps prevent meshing issues by alerting users to geometries that may cause problems during the meshing process.
Changes:
- Added
MIN_GMSH_RADIUSconstant (1e-6) representing OpenCASCADE tolerance - Implemented
_warn_small_cylinder_radiusvalidator that checks cylinder radii and warns when they fall below meshing thresholds - Added comprehensive tests covering both non-tapered and tapered cylinder scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tidy3d/components/tcad/simulation/heat_charge.py | Added imports for Cylinder and traverse_geometries, defined MIN_GMSH_RADIUS constant, and implemented validator to warn about small cylinder radii |
| tests/test_components/test_heat_charge.py | Added test function to verify warnings are issued for small cylinder radii in both non-tapered and tapered cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
12b4bef to
c91f81b
Compare
c91f81b to
61e8eb7
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/components/tcad/simulation/heat_charge.pyLines 388-396 388
389 # Warn if radii are below minimum
390 if is_tapered:
391 if r_bottom < min_radius:
! 392 log.warning(
393 f"Cylinder 'radius_bottom' ({r_bottom:.3e}) is below the minimum "
394 f"radius for meshing ({min_radius:.3e}). The sidewall angle may be "
395 f"too steep. Will be clamped to minimum radius or mesh size, whichever is larger."
396 ) |
61e8eb7 to
9b429c9
Compare
9b429c9 to
1c79e74
Compare
1c79e74 to
0a0063e
Compare
| elif isinstance(geometry, base.ClipOperation): | ||
| yield from traverse_geometries(geometry.geometry_a) | ||
| yield from traverse_geometries(geometry.geometry_b) | ||
| elif isinstance(geometry, base.Transformed): |
There was a problem hiding this comment.
I see, this will have side-effects on other uses of this function too, but this addition actually seems correct here, because a Transformed geometry could itself be a group or a clip operation, and previously we were not traversing those!
There was a problem hiding this comment.
actually, I forgot to ask @weiliangjin2021 about this. I think he's using this somewhere in the backend
There was a problem hiding this comment.
Yes it is definitely used and I was first going to suggest making a separate function but then realized this is more correct. But yeah maybe run backend tests too.
There was a problem hiding this comment.
It looks only used here. Backend is using flatten_group, but not this method
There was a problem hiding this comment.
right, so it seems like it is only used in the frontend and frontend tests pass. I'm guessing it's safe @momchil-flex ?
0a0063e to
8a3b819
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
8a3b819 to
0879f51
Compare
Note
Low Risk
Adds validation-time warnings and geometry traversal changes without altering solver behavior; main risk is noisy/incorrect warnings if the radius threshold logic is off.
Overview
Adds validation-time warnings to
HeatChargeSimulationwhen any (including transformed/nested)Cylinderhasradius/radius_bottom/radius_topbelow a minimum threshold derived from OpenCASCADE tolerance and a relative fraction, helping users avoid gmsh meshing/numerical issues.Updates
traverse_geometries()to descend intoTransformedgeometries so the new checks apply to translated/rotated shapes, adds targeted tests for tiny-radius and steeply-tapered cylinders, and documents the new warning inCHANGELOG.md.Written by Cursor Bugbot for commit 0879f51. This will update automatically on new commits. Configure here.
Greptile Overview
Greptile Summary
This PR adds validation-time warnings for
HeatChargeSimulationwhenCylindergeometries have radii below the minimum threshold required for gmsh/OpenCASCADE meshing. The implementation correctly traverses nested geometries and checks both tapered and non-tapered cylinders.Key Changes:
MIN_GMSH_RADIUSconstant (1e-6) to define OpenCASCADE tolerance_warn_small_cylinder_radiusvalidator that checksradius_bottomandradius_topagainst computed minimumIssues Found:
!=) which can be unreliable; should use tolerance-based comparison withnp.iscloseConfidence Score: 3/5
is_tapereddetection in edge cases. Missing CHANGELOG is a process violation but doesn't affect code quality.tidy3d/components/tcad/simulation/heat_charge.pyline 379 for the float comparison fixImportant Files Changed
Sequence Diagram
sequenceDiagram participant User participant HeatChargeSimulation participant Validator as _warn_small_cylinder_radius participant GeomUtils as traverse_geometries participant Cylinder participant Logger as log.warning User->>HeatChargeSimulation: Create simulation with structures HeatChargeSimulation->>Validator: Validate structures field loop For each structure Validator->>GeomUtils: traverse_geometries(structure.geometry) GeomUtils-->>Validator: Yields nested geometries loop For each geometry alt geometry is Cylinder Validator->>Cylinder: Get radius_bottom Cylinder-->>Validator: r_bottom Validator->>Cylinder: Get radius_top Cylinder-->>Validator: r_top Validator->>Validator: Check if tapered (r_bottom != r_top) Validator->>Validator: Compute min_radius = max(MIN_GMSH_RADIUS, 0.01*max(abs(r_bottom), abs(r_top))) alt is_tapered alt r_bottom < min_radius Validator->>Logger: Warn about radius_bottom end alt r_top < min_radius Validator->>Logger: Warn about radius_top end else not tapered alt r_bottom < min_radius Validator->>Logger: Warn about radius end end end end end Validator-->>HeatChargeSimulation: Return validated structures HeatChargeSimulation-->>User: Simulation created (with warnings)Context used:
dashboard- Use a tolerance-based comparison (e.g., np.isclose) for floating-point numbers instead of direct equ... (source)dashboard- Update the CHANGELOG.md file when making changes that affect user-facing functionality or fix bugs. (source)